home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Menu / c / FontMenu < prev    next >
Text File  |  1995-07-08  |  3KB  |  149 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Menu.GetFlags.c
  12.     Author:  Ben Summers
  13.     Version: 1.00 (21 Oct 94)
  14.     Purpose: Makes a Font menu
  15. */
  16.  
  17. #include <string.h>
  18. #include <stdio.h>
  19.  
  20. #include "DeskLib:Wimp.h"
  21. #include "DeskLib:Menu.h"
  22. #include "DeskLib:SWI.h"
  23.  
  24.  
  25.  
  26.  
  27.   /* minimum version to use font manager font menus * 100 */
  28. #define MIN_NEW_FONT_VERSION 307 
  29.  
  30. #define NEW     0
  31. #define OLD     1
  32. #define UNKNOWN 2
  33.  
  34. #define XFont_CacheAddr 0x40080 + XOS_Bit
  35. #define XFont_ListFonts 0x40091 + XOS_Bit
  36.  
  37. static int version = UNKNOWN;
  38.  
  39. static menu_ptr font_menu = 0;
  40. static int entries;
  41. static int last_ticked = -1;
  42.  
  43. static BOOL new_font_manager(void)
  44. {
  45.   if(version == UNKNOWN) {
  46.     int v;
  47.     if(SWI(0, 1, XFont_CacheAddr, &v) != 0 || v < MIN_NEW_FONT_VERSION) {
  48.       version = OLD;
  49.     } else {
  50.       version = NEW;
  51.     }
  52.   }
  53.  
  54.   return version == NEW;
  55. }
  56.  
  57. menu_ptr Menu_FontMenu(BOOL sysfont, char *tick)
  58. {
  59.   if(new_font_manager()) {
  60.     return Menu_FontMenu3(sysfont, tick);
  61.   } else {
  62.     int l;
  63.  
  64.     if(font_menu == 0) {    /* make the font menu */
  65.       BOOL created = FALSE;
  66.       int count = 0;
  67.       char name[64];
  68.  
  69.       entries = 0;
  70.  
  71.       do {
  72.         if(SWI(4, 3, XFont_ListFonts, 0, (int)name, count, -1, 0, 0, &count) != 0)
  73.           return 0;
  74.  
  75.         if(created == FALSE) {
  76.           char text[128];
  77.           if(sysfont) {
  78.             sprintf(text, "System font,%s", name);
  79.             entries++; 
  80.           }
  81.  
  82.           if((font_menu = Menu_New("Fonts", sysfont?text:name)) == 0)
  83.             return 0;
  84.  
  85.           created = TRUE;
  86.         } else {
  87.           font_menu = Menu_Extend(font_menu, name);
  88.         }
  89.  
  90.         entries++;
  91.  
  92.       } while(count != -1);
  93.     }
  94.  
  95.     if(last_ticked != -1) {
  96.       Menu_SetFlags(font_menu, last_ticked, FALSE, FALSE);
  97.       last_ticked = -1;
  98.     }
  99.  
  100.     if(tick != Menu_FontMenu_NOTICK) {
  101.       if(tick == Menu_FontMenu_TICKSYSFONT) {
  102.         last_ticked = 0;
  103.       } else {
  104.         for(l = 0; l < entries; l++) {
  105.           if(strcmp(Menu_GetText(font_menu, l), tick) == 0) {
  106.             last_ticked = l;
  107.             break;
  108.           }
  109.         }
  110.       }
  111.  
  112.       if(last_ticked != -1) {
  113.         Menu_SetFlags(font_menu, last_ticked, TRUE, FALSE);
  114.         last_ticked = -1;
  115.       }
  116.     }
  117.  
  118.     return menu_fontmenu = font_menu;
  119.  
  120.   }
  121.  
  122.   return 0;
  123. }
  124.  
  125. extern char *Menu_FontMenuDecode(int *selection)
  126. {
  127.   if(new_font_manager()) {
  128.     return Menu_FontMenuDecode3(selection);
  129.   } else {
  130.     return Menu_GetText(font_menu, *selection);
  131.   }
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. /* JS 16 Apr 1995*    */
  139. /* Support for DLL    */
  140. /*
  141. menu_fontmenu is actually defined in FontMenu3.s, but we will put the
  142. veneer function here...
  143. */
  144. #ifdef _DLL
  145. extern menu_ptr menu_fontmenu;
  146. menu_ptr        *Menu__Ref_fontmenu( void)    { return &menu_fontmenu;    }
  147. #endif
  148.  
  149.